import Mock from 'mockjs'
import { result, mockPageRes, qsparse } from '../util'
const mockOrderList = (params) => result(() => {
  const statusText = ['未审核', '审核通过', '审核驳回']
  const status = [0, 1, 2]
  const list = Mock.mock({
    'orderList|1-20': [
      {
        'purchaseNo': '@id',
        'supplierName': '@ctitle',
        'status|+1': status,
        'statusText|+1': statusText,
        'supplierCode': '@natural',
        'purchaseDate': '@date',
        'chargePerson': '@cname',
        'purchaseAmount': '@float(1000, 1500, 2, 2)',
        'purchaseActualAmount': '@float(900, 1000, 2, 2)',
        'addres': '@county(true)',
        'remark': '@cparagraph',
        'creater': '@cname',
        'createTime': '@datetime',
        'updateTime': '@now'
      }
    ]
  })
  return mockPageRes(params, list.orderList)
})
const mockProductList = (params) => result(() => {
  const tag = ['导轨', '滚珠丝杆', '机床丝杆']
  const list = Mock.mock({
    'productList|1-10': [{
      'productCode': '@id',
      'productName': '@cword(3, 5)',
      'tag|1': tag,
      'model': /[A-Z]{3}[0-9]{5}/,
      'productNum|1-100': 80,
      'actualPrice|10-100.2-2': 20,
      'discountRate|0-1.2-2': 1
    }]
  })
  return list.productList
})

const mockUnEntryProductList = () => result(() => {
  const tag = ['导轨', '滚珠丝杆', '机床丝杆']
  const list = Mock.mock({
    'productList|1-10': [{
      'productCode': '@id',
      'productName': '@cword(3, 5)',
      'productTag|1': tag,
      'productModel': /[A-Z]{3}[0-9]{5}/,
      'purchaseNum|20-80': 50,
      'enteredNum|1-20': 5,
      'notEntryNum|20-100': 10
    }]
  })
  return list.productList
})
export default {
  'post|/api/purchase/getOrderInfoList': (option) => {
    const params = qsparse(option.body)
    return mockOrderList(params)
  },
  'post|/api/purchase/getProductList': (option) => {
    const params = qsparse(option.body)
    return mockProductList(params)
  },
  'post|/api/purchase/getUnEntryProductList': (option) => {
    const params = qsparse(option.body)
    return mockUnEntryProductList(params)
  }
}
